home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 10.7 KB | 353 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTxtBox.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWTXTBUF_H
- #include "FWTxtBuf.h"
- #endif
-
- #ifndef FWRASTER_H
- #include "FWRaster.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRANSFORM_
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_TextBoxShape
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CTextBoxShape, FW_CBaseTextShape)
-
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LTextBoxShape, FW_CTextBoxShape, FW_CTextBoxShape::Read, FW_CShape::Write)
-
- //========================================================================================
- // class FW_CTextBoxShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(const FW_CTextBoxShape& other) :
- FW_CBaseTextShape(other),
- fTextBox(other.fTextBox),
- fOptions(other.fOptions)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape() :
- FW_CBaseTextShape(),
- fOptions(kDefaultJustification)
- // fTextBox is set to 0's to its default constructor
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(const FW_CString& string,
- const FW_CRect& box,
- const FW_PFont& font,
- FW_TextBoxOptions options,
- const FW_PInk& ink) :
- FW_CBaseTextShape(string, ink, font),
- fOptions(options),
- fTextBox(box)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(FW_CTextReader* textReader,
- const FW_CRect& box,
- const FW_PFont& font,
- FW_TextBoxOptions options,
- const FW_PInk& ink) :
- FW_CBaseTextShape(textReader, ink, font),
- fOptions(options),
- fTextBox(box)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::FW_CTextBoxShape(FW_CReadableStream& archive) :
- FW_CBaseTextShape(archive)
- {
- archive >> fTextBox;
- archive >> fOptions;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::~FW_CTextBoxShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape::~FW_CTextBoxShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CTextBoxShape& FW_CTextBoxShape::operator=(const FW_CTextBoxShape& other)
- {
- if (this != &other)
- {
- FW_CBaseTextShape::operator=(other);
-
- fTextBox = other.fTextBox;
- fOptions = other.fOptions;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Render(FW_CGraphicContext& gc) const
- {
- FW_CPrivTextBuffer textBuffer(&fString);
- gc.GetRasterizer()->RenderTextBox(gc,
- &textBuffer,
- fTextBox,
- fOptions,
- GetRenderVerb(),
- fInk,
- fFont);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::RenderTextBox
- //----------------------------------------------------------------------------------------
-
- FW_CFixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc,
- FW_CTextReader *textReader,
- const FW_CRect& box,
- const FW_PFont& font,
- FW_TextBoxOptions options,
- const FW_PInk& ink)
- {
- FW_CPrivTextBuffer textBuffer(textReader);
- return gc.GetRasterizer()->RenderTextBox(gc,
- &textBuffer,
- box,
- options,
- FW_kFill,
- ink,
- font);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::RenderTextBox
- //----------------------------------------------------------------------------------------
-
- FW_CFixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc,
- const FW_CString& string,
- const FW_CRect& box,
- const FW_PFont& font,
- FW_TextBoxOptions options,
- const FW_PInk& ink)
- {
- FW_CPrivTextBuffer textBuffer(&string);
- return gc.GetRasterizer()->RenderTextBox(gc,
- &textBuffer,
- box,
- options,
- FW_kFill,
- ink,
- font);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::UpdateTextBox
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::UpdateTextBox(FW_CGraphicContext& gc)
- {
- FW_CPrivTextBuffer textBuffer(&fString);
- gc.GetRasterizer()->TextBoxSize(gc,
- &textBuffer,
- fFont,
- fOptions,
- fTextBox);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::CalcTextBox
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc,
- FW_CTextReader* textReader,
- FW_TextBoxOptions options,
- const FW_PFont& font,
- FW_CRect& box)
- {
- FW_ByteCount savedPosition = textReader->GetPosition();
- FW_CPrivTextBuffer textBuffer(textReader);
- gc.GetRasterizer()->TextBoxSize(gc,
- &textBuffer,
- font,
- options,
- box);
- textReader->SetPosition(savedPosition); // restore original textReader position
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::CalcTextBox
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc,
- const FW_CString& string,
- FW_TextBoxOptions options,
- const FW_PFont& font,
- FW_CRect& box)
- {
- FW_CPrivTextBuffer textBuffer(&string);
- gc.GetRasterizer()->TextBoxSize(gc,
- &textBuffer,
- font,
- options,
- box);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Transform(Environment* ev, ODTransform* odTransform)
- {
- fTextBox.Transform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::InverseTransform(Environment* ev, ODTransform* odTransform)
- {
- fTextBox.InverseTransform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Inset(FW_CFixed x, FW_CFixed y)
- {
- fTextBox.Inset(x, y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CTextBoxShape::Copy() const
- {
- return FW_NEW(FW_CTextBoxShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::MoveShape(FW_CFixed deltaX, FW_CFixed deltaY)
- {
- fTextBox.left += deltaX;
- fTextBox.top += deltaY;
- fTextBox.right += deltaX;
- fTextBox.bottom += deltaY;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::MoveShapeTo(FW_CFixed x, FW_CFixed y)
- {
- fTextBox.right += x - fTextBox.left;
- fTextBox.bottom += y - fTextBox.top;
- fTextBox.left = x;
- fTextBox.top = y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_UNUSED(gc);
-
- rect = fTextBox;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CTextBoxShape::Flatten(FW_CWritableStream& archive) const
- {
- FW_CBaseTextShape::Flatten(archive);
-
- archive << fTextBox;
- archive << fOptions;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextBoxShape::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CTextBoxShape::Read(FW_CReadableStream& archive)
- {
- return FW_NEW(FW_CTextBoxShape, (archive));
- }
-
-